package message

import (
	jsoniter "github.com/json-iterator/go"
)

type source struct {
	Service string `json:"sn,omitempty"`  //服务名称
	Session string `json:"sid,omitempty"` //服务点
	Clerk   string `json:"cid,omitempty"` //服务员
}

func (s *source) Copy() Source {
	return &source{
		Service: s.Service,
		Session: s.Session,
		Clerk:   s.Clerk,
	}
}

func (s *source) Clone(src Source) {
	s.Service = src.ServiceID()
	s.Session = src.SessionID()
	s.Clerk = src.ClerkID()
}

func (s *source) ServiceID() string {
	return s.Service
}

func (s *source) SessionID() string {
	return s.Session
}

func (s *source) ClerkID() string {
	return s.Clerk
}

func (s *source) Clean() {
	s.Service = ""
	s.Session = ""
	s.Clerk = ""
}

func (s *source) FromJson(js string) error {
	return jsoniter.ConfigFastest.UnmarshalFromString(js, s)
}

func (s *source) ToJson() string {
	js, _ := jsoniter.ConfigFastest.MarshalToString(s)
	return js
}
